package session.stateless;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import session.TX.AreaSBRemote;
import entity.OutletSeatArea;
import Helper.Helper_Area;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Lu Xiaodi
 */
public class AreaBeanTest1 {

    private AreaSBRemote areaBean = lookupTierManagementBeanRemote();

    private AreaSBRemote lookupTierManagementBeanRemote() {
        try {
            Context c = new InitialContext();
            return (AreaSBRemote) c.lookup("java:global/Foodsage/Foodsage-ejb/AreaSB!session.TX.AreaSBRemote");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    @Test
    public void testGetAllAreas0() {
        List<OutletSeatArea> list = areaBean.getAllAreas(new Long(10019));
        assertEquals("list.size()", 0, list.size());
    }

    @Test
    public void testGetAllHelperAreas0() {
        List<Helper_Area> list = areaBean.getAllHelperAreas(new Long(10019));
        assertEquals("list.size()", 0, list.size());
    }

    @Test
    public void testAddArea() {
        areaBean.addArea(new Long(10019), "Area 2-1-A", "Area 2-1-A path");
        List<Helper_Area> list = areaBean.getAllHelperAreas(new Long(10019));
        Integer size = list.size();
        assertEquals("list.size()", new Integer(1), size);
    }

    @Test
    public void testAddAreaConflict() {
        areaBean.addArea(new Long(10019), "Area 2-1-A", "Area 2-1-A path");
        List<Helper_Area> list = areaBean.getAllHelperAreas(new Long(10019));
        Integer size = list.size();
        assertEquals("list.size()", new Integer(1), size);
    }
    
    @Test
    public void testDeleteArea(){
        Long areaId = areaBean.getAllHelperAreas(new Long(10019)).get(0).getId();
        areaBean.removeArea(new Long(10019), areaId);
        List<OutletSeatArea> list = areaBean.getAllAreas(new Long(10019));
        Integer size = list.size();
        assertEquals("list.size()", new Integer(0), size);
    }

    @Test
    public void testSaveArea() {
        List<Helper_Area> list = areaBean.getAllHelperAreas(new Long(10017));
        assertEquals("list.size()", 1, list.size());
        Helper_Area area = list.get(0);
        areaBean.saveArea(area);
        assertEquals("Area 1-1-A", area.getAreaName());
        
        area.setAreaName("Area 1-1-A (copy)");
        areaBean.saveArea(area);


        List<Helper_Area> testList = areaBean.getAllHelperAreas(new Long(10017));
        assertEquals("testList.size()", 1, testList.size());
        Helper_Area testArea = list.get(0);
        assertEquals("Area 1-1-A (copy)", testArea.getAreaName());
        
        testArea.setAreaName("Area 1-1-A");
        areaBean.saveArea(testArea);
    }

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() {
    }
    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}
}
